# coding:utf-8
import configDB as Mysql_Db
import public_method as pub
import time,datetime
import filelog
startTime=datetime.datetime.strptime("2018-03-16 03:06:43", '%Y-%m-%d %H:%M:%S')
v5_sqlMapper=Mysql_Db.Mysql('DATABASE_1')
#数据清空操作
del_webList = v5_sqlMapper.get_all("select new_id from data_conversion_info where new_table='public_web_config'")
if del_webList:
    for web_num in range(len(del_webList)):
        del_webId = int(del_webList[web_num][0])
        # 清除站点数据
        v5_sqlMapper.delete("delete from public_web_config where id=" + str(del_webId))
        # 清除站点配置项数据
        v5_sqlMapper.delete("delete from public_configuration_item where web_id=" + str(del_webId))
        # 清除站点模块配置信息数据
        v5_sqlMapper.delete("delete from public_config_mode where web_id=" + str(del_webId))
        # 清除默认留言配置数据
        v5_sqlMapper.delete("delete from basic_leave_message_config where web_id=" + str(del_webId))
        # 清除系统配置信息license_sys
        v5_sqlMapper.delete("delete from public_web_sys where web_id=" + str(del_webId))
        # 清除用户权限数据
        v5_sqlMapper.delete("delete from public_user_role where user_id in(select id from public_user where web_id="+ str(del_webId)+ ")")
        # 清除所有站点用户数据
        v5_sqlMapper.delete("delete from public_user  where web_id=" + str(del_webId))
        # 清除所有站点分组数据
        v5_sqlMapper.delete("delete from public_group where web_id=" + str(del_webId))
        # 清除所有角色资源数据
        v5_sqlMapper.delete("delete from public_role_resource where role_id in(select id from public_role where web_id="+ str(del_webId)+ ")")
        # 清除所有角色分类数据
        v5_sqlMapper.delete("delete from public_role_classes where role_id in(select id from public_role where web_id="+ str(del_webId)+ ")")
        # 清除角色数据
        v5_sqlMapper.delete(  "delete from public_role where web_id=" + str(del_webId))
        # 清除问题分类数据
        v5_sqlMapper.delete("delete from kn_classes where web_id=" + str(del_webId))
        # 清除知识分类标签
        v5_sqlMapper.delete("delete from kn_knowledge_label where web_id=" + str(del_webId))
        # 清除访客角色表数据
        v5_sqlMapper.delete("delete from public_chatuser_role where web_id=" + str(del_webId))
        # 清除素材数据
        v5_sqlMapper.delete("delete from public_material where web_id=" + str(del_webId))
        # 清除图文信息
        v5_sqlMapper.delete("delete from public_image_text where web_id=" + str(del_webId))
        # 清除图文明细信息
        v5_sqlMapper.delete("delete from public_image_text_details where web_id=" + str(del_webId))
        # 清除渠道信息
        v5_sqlMapper.delete("delete from ch_channel_config where web_id=" + str(del_webId))
        # 清除渠道明细信息
        v5_sqlMapper.delete("delete from ch_channel_detail where web_id=" + str(del_webId))
        # 清除渠道配置页信息
        v5_sqlMapper.delete("delete from ch_page_config where web_id=" + str(del_webId))
        # 清除微信渠道配置信息
        v5_sqlMapper.delete("delete from ch_wx_config where web_id=" + str(del_webId))
        # 清除知识点信息
        v5_sqlMapper.delete("delete from kn_knowledge where web_id=" + str(del_webId))
        # 清除知识点配置信息
        v5_sqlMapper.delete("delete from kn_knowledge_config where web_id=" + str(del_webId))
        # 清除知识信息
        v5_sqlMapper.delete("delete from kn_question where web_id=" + str(del_webId))
        # 清除答案信息
        v5_sqlMapper.delete("delete from kn_answer where web_id=" + str(del_webId))
        # 清除答案配置项信息
        v5_sqlMapper.delete("delete from kn_answer_config where web_id=" + str(del_webId))
        # 清除词汇信息
        v5_sqlMapper.delete("delete from kn_word_doc where web_id=" + str(del_webId))
        # 清除词汇分类信息
        v5_sqlMapper.delete("delete from kn_word_group where web_id=" + str(del_webId))
        # 清除词汇分支信息
        v5_sqlMapper.delete("delete from kn_word_relation where web_id=" + str(del_webId))
        # 清除来访者属性信息
        v5_sqlMapper.delete("delete from public_chatuser_role_pro where web_id=" + str(del_webId))
        # 清除分组信息
        v5_sqlMapper.delete("delete from public_chatuser_role_pro_relation")

    v5_sqlMapper.delete("delete from data_tables_info")
    v5_sqlMapper.delete("delete from data_conversion_info")
    v5_sqlMapper.dispose()
    endTime=datetime.datetime.strptime("2018-03-16 03:06:43", '%Y-%m-%d %H:%M:%S')
    filelog.logInfo('本次数据转换开始于:' + str(startTime) + '终止于:' + str(endTime),'info')
else:
    print("无数据待清理！")
    '''
    v5_sqlMapper.insert(pub.insert_tables('kn_classes', 'classes', new_database, old_database, class_num, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_knowledge_label', 'label', new_database, old_database, lable_num, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('public_chatuser_role', 'hc_comb', new_database, old_database, hcComb_num, v5_webId,v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('public_material', 'material', new_database, old_database, material_num, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('public_image_text', 'wxappmsg', new_database, old_database, wxapp_num, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('public_image_text_details', 'wxappmsg_detail', new_database, old_database, wxDetail_num,v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('ch_channel_config', 'ch_source_config', new_database, old_database, channel_num, v5_webId,v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('ch_channel_detail', 'ch_source_config', new_database, old_database, channel_detailNum,v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('ch_page_config', 'ch_source_config', new_database, old_database, channel_pageNum, v5_webId,v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('ch_wx_config', 'ch_source_config', new_database, old_database, channel_wxConfigNum, v5_webId,v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_knowledge', 'solution', new_database, old_database, solution_num, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_knowledge_config', 'solution', new_database, old_database, solution_classNum, v5_webId,v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_knowledge_config', 'solution_config', new_database, old_database, solution_configNum,v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_question', 'question_1', new_database, old_database, question_num, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_answer', 'answer', new_database, old_database, answer_num, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_answer_config', 'answer_config', new_database, old_database, answer_channelNum, v5_webId,v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_question', 'question_0', new_database, old_database, sim_questionNum, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_word_doc', 'worddoc', new_database, old_database, word_num, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_word_group', 'worddoc', new_database, old_database, word_groupNum, v5_webId, v4_webId))
    v5_sqlMapper.insert(pub.insert_tables('kn_word_relation', 'worddoc', new_database, old_database, word_relationNum, v5_webId,v4_webId))
    '''